const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('SysMenu', {
    menuId: {
      field:'menu_id',  // 数据库中的字段名
      autoIncrement: true,  // 是否自动增
      type: DataTypes.BIGINT,
      allowNull: false,
      primaryKey: true,
      comment: "菜单ID"
    },
    menuName: {
      field:'menu_name',
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: "菜单名称"
    },
    parentId: {
      field:'parent_id',
      type: DataTypes.BIGINT,
      allowNull: true,
      defaultValue: 0,
      comment: "父菜单ID"
    },
    orderNum: {
      field:'order_num',
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: "显示顺序"
    },
    url: {
      type: DataTypes.STRING(200),
      allowNull: true,
      defaultValue: "#",
      comment: "请求地址"
    },
    target: {
      type: DataTypes.STRING(20),
      allowNull: true,
      defaultValue: "",
      comment: "打开方式（menuItem页签 menuBlank新窗口）"
    },
    menuType: {
      field:'menu_type',
      type: DataTypes.CHAR(1),
      allowNull: true,
      defaultValue: "",
      comment: "菜单类型（M目录 C菜单 F按钮）"
    },
    visible: {
      type: DataTypes.CHAR(1),
      allowNull: true,
      defaultValue: "0",
      comment: "菜单状态（0显示 1隐藏）"
    },
    isRefresh: {
      field:'is_refresh',
      type: DataTypes.CHAR(1),
      allowNull: true,
      defaultValue: "1",
      comment: "是否刷新（0刷新 1不刷新）"
    },
    perms: {
      type: DataTypes.STRING(100),
      allowNull: true,
      comment: "权限标识"
    },
    icon: {
      type: DataTypes.STRING(100),
      allowNull: true,
      defaultValue: "#",
      comment: "菜单图标"
    },
    createdBy: {
      field:'create_by',
      type: DataTypes.STRING(64),
      allowNull: true,
      defaultValue: "",
      comment: "创建者"
    },
    createdAt: {
      field:'create_time',
      type: DataTypes.DATE,
      allowNull: true,
      comment: "创建时间"
    },
    updatedBy: {
      field:'update_by',
      type: DataTypes.STRING(64),
      allowNull: true,
      defaultValue: "",
      comment: "更新者"
    },
    updatedAt: {
      field:'update_time',
      type: DataTypes.DATE,
      allowNull: true,
      comment: "更新时间"
    },
    remark: {
      type: DataTypes.STRING(500),
      allowNull: true,
      defaultValue: "",
      comment: "备注"
    }
  }, {
    sequelize,
    tableName: 'sys_menu',
    timestamps: false,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        // 将数据库字段的下划线命名格式转换为驼峰命名格式
        underscored: true,
        fields: [
          { name: "menu_id" },
        ]
      },
    ]
  });
};
